package com.smartcruise.base;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.smartcruise.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by FengChaoQun
 * on 2018/1/20 0020
 * 包含标准标题栏的activity
 */

@SuppressLint("Registered")
public abstract class BaseTitleActivity extends BaseActivity {

    @BindView(R.id.leftArrow)
    ImageView leftArrow;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.container)
    FrameLayout container;
    @BindView(R.id.rightImage)
    ImageView rightImage;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.util_title);
        if (getContentLayout() > 0) {
            View.inflate(getActivity(), getContentLayout(), (ViewGroup) findViewById(R.id.container));
        }
        ButterKnife.bind(this);
        initBase();
    }

    private void initBase() {
        TitleBuilder titleBuilder = getTitleBuilder();
        if (titleBuilder != null) {
            title.setText(titleBuilder.getTitle());
            leftArrow.setVisibility(titleBuilder.isShowLeftArrow() ? View.VISIBLE : View.GONE);
            rightImage.setVisibility(titleBuilder.isShowRightImage() ? View.VISIBLE : View.GONE);
            if (titleBuilder.getRightImageSrc() > 0) {
                rightImage.setImageResource(titleBuilder.getRightImageSrc());
            }
        }
        init();
    }

    protected abstract void init();

    protected abstract int getContentLayout();

    protected abstract TitleBuilder getTitleBuilder();

    protected void clickOnBack() {
        finish();
    }

    protected void clickOnRightImage() {

    }

    @OnClick(R.id.leftArrow)
    public void onLeftArrowClicked() {
        clickOnBack();
    }

    @OnClick(R.id.rightImage)
    public void onRightImageClicked() {
        clickOnRightImage();
    }
}
